<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="老师名字" prop="teacherId">
        <el-input
          v-model="queryParams.teacherId"
          placeholder="请输入老师名字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考核月份" prop="registrationTime">
        <el-date-picker clearable
          v-model="queryParams.registrationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择考核月份">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="getsmList"
        >生成本月绩效</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="examineSm"
          v-hasPermi="['performance:scoring:edit']"
        >完成审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['performance:scoring:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['performance:scoring:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scoringList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="老师名字" align="center" prop="teacherId" />
      <el-table-column label="考核月份" align="center" prop="registrationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationTime, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="entryName" />
      <el-table-column label="目标值" align="center" prop="targetValue" />
      <el-table-column label="自评分数" align="center" prop="selfscore" />
      <el-table-column label="自评备注" align="center" prop="selfcontext" />
      <el-table-column label="审核分数" align="center" prop="reviewScore" />
      <el-table-column label="审核备注" align="center" prop="reviewRemarks" />
      <el-table-column label="项目权重" align="center" prop="weight" />
      <el-table-column label="审核人名称" align="center" prop="reviewNameId" />
      <el-table-column label="审核状态(0:未审核;1已经审核)" align="center" prop="reviewStatus" >
        <template slot-scope="scope">
          <span v-if="scope.row.reviewStatus === 0">未审核</span>
          <span v-if="scope.row.reviewStatus === 1">已审核</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="examineSm(scope.row)"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['performance:scoring:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"

    />

    <!-- 审核框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核分数" prop="reviewScore">
          <el-input v-model="form.reviewScore" placeholder="请输入审核分数" />
        </el-form-item>
        <el-form-item label="审核备注" prop="reviewRemarks">
          <el-input v-model="form.reviewRemarks" placeholder="请输入审核备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listScoring,
  getScoring,
  delScoring,
  addScoring,
  updateScoring,
  getALLScoring,
  examineScoring
} from "@/api/performance/scoring";
import {listTeacherType} from "@/api/teacher/teacher";
import {getTeacherType} from "@/api/performance/template";
import {addData, getTeacherNameData, updateData} from "@/api/performance/data";
import Template from "@/views/performance/template/index.vue";

export default {
  name: "Scoring",
  components: {Template},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考核打分表格数据
      scoringList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherId: null,
        registrationTime: null,
        reviewStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {

  },
  methods: {
    // 提交审核
    submitForm(){
      examineScoring(this.form).then(response=>{
        console.log(response);
        this.open=false;
        this.form.reviewRemarks=null;
        this.form.reviewScore=null;
        this.getsmList();
      })
    },
    // 审核按钮
    examineSm(row){
      this.form.id=row.id
      this.open=true;
    },
    getsmList(){
      this.loading = true;
      getALLScoring().then(response=>{
        this.scoringList = response;
        this.loading = false;
      });
      getTeacherNameData().then(response=>{
        console.log(response.data.teacherType);
        let param=response.data.teacherType;

      })


    },


    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        teacherId: null,
        registrationTime: null,
        numberDay: null,
        trainingDays: null,
        classTutoringId: null,
        recommendedNumber: null,
        realityNumber: null,
        mockInterview: null,
        projectDefense: null,
        totalDays: null,
        goalThisMonth: null,
        reviewScore: null,
        reviewRemarks: null,
        reviewNameId: null,
        reviewStatus: null,
        notes: null,
        goalLastMonth: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考核打分";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getScoring(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改考核打分";
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除考核打分编号为"' + ids + '"的数据项？').then(function() {
        return delScoring(ids);
      }).then(() => {
        this.getsmList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('performance/scoring/export', {
        ...this.queryParams
      }, `scoring_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
